﻿using System;
using System.Data;
using System.Collections.Generic;

using Catering_Model;
namespace Catering_Rules
{
	/// <summary>
	/// RawInventory
	/// </summary>
	public partial class RawInventory
	{
		private readonly Catering_Operation.RawInventory dal=new Catering_Operation.RawInventory();
		public RawInventory()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			return dal.Exists(id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(Catering_Model.RawInventory model)
		{
			dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Catering_Model.RawInventory model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			
			return dal.Delete(id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			return dal.DeleteList(idlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Catering_Model.RawInventory GetModel(int id)
		{
			
			return dal.GetModel(id);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Catering_Model.RawInventory GetModelByCache(int id)
		{
			
			string CacheKey = "RawInventoryModel-" + id;
			object objModel = Catering_DBOpertion.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(id);
					if (objModel != null)
					{
						int ModelCache = Catering_DBOpertion.ConfigHelper.GetConfigInt("ModelCache");
						Catering_DBOpertion.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Catering_Model.RawInventory)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Catering_Model.RawInventory> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Catering_Model.RawInventory> DataTableToList(DataTable dt)
		{
			List<Catering_Model.RawInventory> modelList = new List<Catering_Model.RawInventory>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Catering_Model.RawInventory model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Catering_Model.RawInventory();
					if(dt.Rows[n]["id"]!=null && dt.Rows[n]["id"].ToString()!="")
					{
						model.id=int.Parse(dt.Rows[n]["id"].ToString());
					}
					if(dt.Rows[n]["GROPID"]!=null && dt.Rows[n]["GROPID"].ToString()!="")
					{
						model.GROPID=int.Parse(dt.Rows[n]["GROPID"].ToString());
					}
					if(dt.Rows[n]["ClassID"]!=null && dt.Rows[n]["ClassID"].ToString()!="")
					{
						model.ClassID=int.Parse(dt.Rows[n]["ClassID"].ToString());
					}
					if(dt.Rows[n]["DBID"]!=null && dt.Rows[n]["DBID"].ToString()!="")
					{
						model.DBID=int.Parse(dt.Rows[n]["DBID"].ToString());
					}
					if(dt.Rows[n]["RAWID"]!=null && dt.Rows[n]["RAWID"].ToString()!="")
					{
						model.RAWID=int.Parse(dt.Rows[n]["RAWID"].ToString());
					}
					if(dt.Rows[n]["RAWName"]!=null && dt.Rows[n]["RAWName"].ToString()!="")
					{
					model.RAWName=dt.Rows[n]["RAWName"].ToString();
					}
					if(dt.Rows[n]["Inventory"]!=null && dt.Rows[n]["Inventory"].ToString()!="")
					{
						model.Inventory=decimal.Parse(dt.Rows[n]["Inventory"].ToString());
					}
					if(dt.Rows[n]["Price"]!=null && dt.Rows[n]["Price"].ToString()!="")
					{
						model.Price=decimal.Parse(dt.Rows[n]["Price"].ToString());
					}
					if(dt.Rows[n]["AmountMoney"]!=null && dt.Rows[n]["AmountMoney"].ToString()!="")
					{
						model.AmountMoney=decimal.Parse(dt.Rows[n]["AmountMoney"].ToString());
					}
					if(dt.Rows[n]["Qualified"]!=null && dt.Rows[n]["Qualified"].ToString()!="")
					{
						model.Qualified=int.Parse(dt.Rows[n]["Qualified"].ToString());
					}
					if(dt.Rows[n]["UnQualified"]!=null && dt.Rows[n]["UnQualified"].ToString()!="")
					{
						model.UnQualified=int.Parse(dt.Rows[n]["UnQualified"].ToString());
					}
					if(dt.Rows[n]["RAWTID"]!=null && dt.Rows[n]["RAWTID"].ToString()!="")
					{
						model.RAWTID=int.Parse(dt.Rows[n]["RAWTID"].ToString());
					}
					if(dt.Rows[n]["RAWIDS"]!=null && dt.Rows[n]["RAWIDS"].ToString()!="")
					{
						model.RAWIDS=int.Parse(dt.Rows[n]["RAWIDS"].ToString());
					}
					if(dt.Rows[n]["Back"]!=null && dt.Rows[n]["Back"].ToString()!="")
					{
					model.Back=dt.Rows[n]["Back"].ToString();
					}
					if(dt.Rows[n]["Statistical"]!=null && dt.Rows[n]["Statistical"].ToString()!="")
					{
						model.Statistical=DateTime.Parse(dt.Rows[n]["Statistical"].ToString());
					}
					if(dt.Rows[n]["temp1"]!=null && dt.Rows[n]["temp1"].ToString()!="")
					{
					model.temp1=dt.Rows[n]["temp1"].ToString();
					}
					if(dt.Rows[n]["temp2"]!=null && dt.Rows[n]["temp2"].ToString()!="")
					{
					model.temp2=dt.Rows[n]["temp2"].ToString();
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Catering_Model.RawInventory> GetAllList(int num)
        {
            List<Catering_Model.RawInventory> listInfo = new List<Catering_Model.RawInventory>();
            DataTable dt = GetList("").Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Catering_Model.RawInventory temp = new Catering_Model.RawInventory();
                temp.id = Int32.Parse(dt.Rows[i]["id"].ToString());
                temp.RAWIDS = Int32.Parse(dt.Rows[i]["RAWIDS"].ToString());
                temp.RAWName = dt.Rows[i]["RAWName"].ToString();
                listInfo.Add(temp);
            }

            return listInfo;
        }


		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

